#include "media_osd.h"

#include <inttypes.h>
#include <string.h>
#include <sys/time.h>
#include <vector>
#include <cassert>
#include <memory>
#include "base_log.h"
#include "common_config_manager.h"
#include "camera_video_enc.h"

namespace El {
namespace Media {

OSDManager &OSDManager::GetInstance()
{
    static OSDManager instance;
    return instance;
}

OSDManager::OSDManager() {}

OSDManager::~OSDManager() {}

bool OSDManager::Start()
{
    // 监听配置变化
    osdHandle_ = Common::ConfigManager::GetInstance().RegisterVerify("osd", [this](const nlohmann::json &config) {
        LOG_INFO("osd config changed: {}", config.dump().c_str());

        if (config["enable"].get<bool>()) {
            Hal::ICameraVideoEnc::GetInstance(0, 0).SetOSD(true);
        } else {
            Hal::ICameraVideoEnc::GetInstance(0, 0).SetOSD(false);
        }
        return true;
    });

    auto osd = Common::ConfigManager::GetInstance().GetConfig("osd");
    if (osd.is_null() || osd["enable"].get<bool>()) {
        Hal::ICameraVideoEnc::GetInstance(0, 0).SetOSD(true);
    } else {
        Hal::ICameraVideoEnc::GetInstance(0, 0).SetOSD(false);
    }
    return true;
}

void OSDManager::Stop() {}

} // namespace Media
} // namespace El